define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/goods/index' + location.search,
                    add_url: 'order/goods/add',
                    edit_url: 'order/goods/edit',
                    del_url: 'order/goods/del',
                    multi_url: 'order/goods/multi',
                    import_url: 'order/goods/import',
                    table: 'order_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'spec_id', title: __('Spec_id')},
                        {field: 'goods_num', title: __('Goods_num')},
                        {field: 'goods_name', title: __('Goods_name'), operate: 'LIKE'},
                        {field: 'goods_price', title: __('Goods_price'), operate:'BETWEEN'},
                        {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'points', title: __('Points'), operate:'BETWEEN'},
                        {field: 'discount_fee', title: __('Discount_fee'), operate:'BETWEEN'},
                        {field: 'pay_fee', title: __('Pay_fee'), operate:'BETWEEN'},
                        {field: 'goods_type', title: __('Goods_type'), searchList: {"1":__('Goods_type 1'),"2":__('Goods_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'goods.id', title: __('Goods.id')},
                        {field: 'goods.first_cate', title: __('Goods.first_cate')},
                        {field: 'goods.two_cate', title: __('Goods.two_cate')},
                        {field: 'goods.title', title: __('Goods.title'), operate: 'LIKE'},
                        {field: 'goods.image', title: __('Goods.image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'goods.images', title: __('Goods.images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'goods.description', title: __('Goods.description'), operate: 'LIKE'},
                        {field: 'goods.createtime', title: __('Goods.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'goods.updatetime', title: __('Goods.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'goods.deletetime', title: __('Goods.deletetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'goods.status', title: __('Goods.status'), formatter: Table.api.formatter.status},
                        {field: 'goods.specjson', title: __('Goods.specjson'), operate: 'LIKE'},
                        {field: 'goods.yue', title: __('Goods.yue')},
                        {field: 'goods.tags', title: __('Goods.tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'goods.pay_auth', title: __('Goods.pay_auth')},
                        {field: 'goods.type', title: __('Goods.type')},
                        {field: 'goods.province', title: __('Goods.province'), operate: 'LIKE'},
                        {field: 'goods.city', title: __('Goods.city'), operate: 'LIKE'},
                        {field: 'goods.area', title: __('Goods.area'), operate: 'LIKE'},
                        {field: 'goods.address', title: __('Goods.address'), operate: 'LIKE'},
                        {field: 'goods.sales', title: __('Goods.sales')},
                        {field: 'spec.id', title: __('Spec.id')},
                        {field: 'spec.spec_name', title: __('Spec.spec_name'), operate: 'LIKE'},
                        {field: 'spec.original_price', title: __('Spec.original_price'), operate:'BETWEEN'},
                        {field: 'spec.price', title: __('Spec.price'), operate:'BETWEEN'},
                        {field: 'spec.goods_id', title: __('Spec.goods_id')},
                        {field: 'spec.stock', title: __('Spec.stock')},
                        {field: 'order.id', title: __('Order.id')},
                        {field: 'order.user_id', title: __('Order.user_id')},
                        {field: 'order.sn', title: __('Order.sn'), operate: 'LIKE'},
                        {field: 'order.total_num', title: __('Order.total_num')},
                        {field: 'order.total_fee', title: __('Order.total_fee'), operate:'BETWEEN'},
                        {field: 'order.pay_type', title: __('Order.pay_type')},
                        {field: 'order.transaction_id', title: __('Order.transaction_id'), operate: 'LIKE'},
                        {field: 'order.createtime', title: __('Order.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.paytime', title: __('Order.paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.address_id', title: __('Order.address_id')},
                        {field: 'order.contact', title: __('Order.contact'), operate: 'LIKE'},
                        {field: 'order.telephone', title: __('Order.telephone'), operate: 'LIKE'},
                        {field: 'order.address', title: __('Order.address'), operate: 'LIKE'},
                        {field: 'order.order_status', title: __('Order.order_status'), formatter: Table.api.formatter.status},
                        {field: 'order.express_com', title: __('Order.express_com'), operate: 'LIKE'},
                        {field: 'order.express_no', title: __('Order.express_no'), operate: 'LIKE'},
                        {field: 'order.discount_fee', title: __('Order.discount_fee'), operate:'BETWEEN'},
                        {field: 'order.sendtime', title: __('Order.sendtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.pay_fee', title: __('Order.pay_fee'), operate:'BETWEEN'},
                        {field: 'order.order_type', title: __('Order.order_type')},
                        {field: 'order.province', title: __('Order.province'), operate: 'LIKE'},
                        {field: 'order.city', title: __('Order.city'), operate: 'LIKE'},
                        {field: 'order.area', title: __('Order.area'), operate: 'LIKE'},
                        {field: 'order.regio', title: __('Order.regio'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
